/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package aso.upna.threads;

import aso.upna.cancion.AbstractCancion;
import aso.upna.config.ClientConfig;
import aso.upna.exceptions.MediaPlayerNotReady;
import aso.upna.exceptions.NoFileLoaded;
import cliente.Reproductor;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author triki
 */
public class PlayingThread extends Thread {

    private ClientConfig main_conf;
    private AbstractCancion cancion;
    private String readFrom;
    private Reproductor rep;
    
    public PlayingThread(Reproductor rep,ClientConfig conf,AbstractCancion can)
    {
        main_conf = conf;
        cancion = can;
        this.rep = rep;
        
        if(cancion.is_local())
        {
            readFrom = cancion.getRealPath();
        }
        else
        {
            readFrom = main_conf.getPathToTempFile();
        }
    }

    public void run()
    {
        try
        {
            rep.setFileName(readFrom);
            rep.play();
        }
        catch(MediaPlayerNotReady ex)
        {
            ex.printStackTrace();
        }
        catch (NoFileLoaded ex)
        {
            ex.printStackTrace();
        }
    }
}
